'use strict';
var React=require( 'react');
var reactDom=require( 'react-dom/server');
var reactRedux=require('react-redux');
var configureStore=require('../public/javascripts/stores/index.js');
var HkfsAbout=require( '../public/javascripts/containers/pc/HkfsAbout.jsx');
var Provider=reactRedux.Provider;
const store = configureStore();
var ModelRender=require('./modelRender.jsx');
var actions=require('../public/javascripts/actions/about');
var async = require('async');
var HttpOperate = require('../nodeLibrary/HttpOperate');
var backEndUrl=require('../nodeConfig/environmentConfig');
var httpOperateForHK = new HttpOperate(backEndUrl.hkBackEndUrl);

exports.RenderFunc=(renderCallBack)=>{
  /*  let processItems=JSON.parse('[{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"}]');
    let egoItems=JSON.parse('[{"title":"公司荣誉1","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉2","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉3","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉4","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉5","imgSrc":"./images/pc/company_img_-Certificate.png"}]');
    let leaders=JSON.parse('[{"name":"汪振武","position":"董事长","content":"个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍","mainImg":"./images/pc/team_img_boss.png"},{"name":"黄健翔","position":"总经理","content":"个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍","mainImg":"./images/pc/team_img_boss2.png"}]');
    let team=JSON.parse('[{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"}]')
    let positionItems=JSON.parse('[{"name":"产品经理","content":"<ul><li>sdf1</li><li>sdf2</li><li>sdf3</li><li>sdf4</li></ul>"},{"name":"IFA招聘","content":"<ul><li>sdf1</li><li>sdf2</li><li>sdf3</li><li>sdf4</li></ul>"}]');
    let dynamicsDetail=JSON.parse('{"page":1,"totalPage":10,"content":[{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数1","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数12","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数13","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数13","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数12","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数12","rightTitle":"2016-05-11"}]}');

    store.dispatch(actions.receiveProcessItems(processItems));
    store.dispatch(actions.receiveEgoItems(egoItems));
    store.dispatch(actions.receiveLeaderItems(leaders));
    store.dispatch(actions.receiveTeamItems(team));
    store.dispatch(actions.receivePositionItems(positionItems));
    store.dispatch(actions.receiveNewsDetail(dynamicsDetail));

    if(renderCallBack) {
        var modelRender=new ModelRender();
        var main = reactDom.renderToString(
            <Provider store={store}>
                <HkfsAbout/>
            </Provider>
        );
        var initializeStore = JSON.stringify(store.getState());
        renderCallBack(modelRender.headerRender(),modelRender.barRender(),modelRender.footerRender(),main, initializeStore);
    }*/

    async.parallel({
        //发展历程
        getProcessItems:(callBack)=>{
            httpOperateForHK.httpGet('/api/facade/company/development',(result)=>{
                let processItems;
                if(result.resultCode=='200'){
                    processItems=result.result;
                    store.dispatch(actions.receiveProcessItems(processItems));
                }
                callBack();
            });
          /*  let processItems=JSON.parse('[{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"},{"time":"2016年七月","content":"测试车上时发生的范德萨范德萨范德萨范德萨"}]');
            store.dispatch(actions.receiveProcessItems(processItems));
            callBack();*/
        },

        //公司荣誉
        getEgoItems:(callBack)=>{
            httpOperateForHK.httpGet('/api/facade/company/glories',(result)=>{
                let egoItems;
                if(result.resultCode=='200'){
                    egoItems=result.result;
                    store.dispatch(actions.receiveEgoItems(egoItems));
                }
                callBack();
            });

           /* let egoItems=JSON.parse('[{"title":"公司荣誉1","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉2","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉3","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉4","imgSrc":"./images/pc/company_img_-Certificate.png"},{"title":"公司荣誉5","imgSrc":"./images/pc/company_img_-Certificate.png"}]');
            store.dispatch(actions.receiveEgoItems(egoItems));
            callBack();*/
        },
        //团队领袖
        getLeaders:(callBack)=>{
            httpOperateForHK.httpGet('/api/facade/company/leader',(result)=>{
                let leaders;
                if(result.resultCode=='200'){
                    leaders=result.result;
                    store.dispatch(actions.receiveLeaderItems(leaders));
                }
                callBack();
            });

            /*let leaders=JSON.parse('[{"name":"汪振武","position":"董事长","content":"个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍","mainImg":"./images/pc/team_img_boss.png"},{"name":"黄健翔","position":"总经理","content":"个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍个人介绍","mainImg":"./images/pc/team_img_boss2.png"}]');
            store.dispatch(actions.receiveLeaderItems(leaders));
            callBack();*/
        },
        //优秀团队
        getTeam:(callBack)=>{
            httpOperateForHK.httpGet('/api/facade/company/team',(result)=>{
                let team;
                if(result.resultCode=='200'){
                    team=result.result;
                    store.dispatch(actions.receiveTeamItems(team));
                }
                callBack();
            });

          /*  let team=JSON.parse('[{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"},{"reImgSrc":"./images/pc/company_img_mascot.png","name":"sdfsdfdsf","content":"测试测是","backContent":"是的范德萨范德萨反倒是"}]')
            store.dispatch(actions.receiveTeamItems(team));
            callBack();*/
        },
        //招聘职位
        getPositionItems:(callBack)=>{
            httpOperateForHK.httpGet('/api/facade/company/jobs',(result)=>{
                let positionItems;
                if(result.resultCode=='200'){
                    positionItems=result.result;
                    store.dispatch(actions.receivePositionItems(positionItems));
                }
                callBack();
            });
            /*let positionItems=JSON.parse('[{"name":"产品经理","content":"<ul><li>sdf1</li><li>sdf2</li><li>sdf3</li><li>sdf4</li></ul>"},{"name":"IFA招聘","content":"<ul><li>sdf1</li><li>sdf2</li><li>sdf3</li><li>sdf4</li></ul>"}]');
            store.dispatch(actions.receivePositionItems(positionItems));
            callBack();*/
        },
        //华康新闻
        getDynamicsDetail:(callBack)=>{
            httpOperateForHK.httpGet('/api/article/type/NEWS?channel=0&curPage=0&pageSize=10', (result)=> {
                if (result.resultCode == '200') {
                   // let dynamicsDetail=JSON.parse('{"page":1,"totalPage":10,"content":[{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数1","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数12","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数13","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数13","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数12","rightTitle":"2016-05-11"},{"reHref":"/dsf/sdf/sdf","leftTitle":"测试测试长度分数分数分数12","rightTitle":"2016-05-11"}]}');
                    let dynamicsDetail = {page: 1, totalPage:  Math.ceil(result.size/10), content: []};
                    for (var i = 0; i < result.result.length; i++) {
                        var resultItem = result.result[i];
                        var contentItem = {
                            reHref: '/hkfsDetail?id='+resultItem.id,
                            leftTitle: resultItem.title,
                            rightTitle: resultItem.ctsStr
                        };
                        dynamicsDetail.content.push(contentItem);
                    }
                    store.dispatch(actions.receiveNewsDetail(dynamicsDetail));
                }
                callBack();
            });
        }
    },
        (err, results)=> {
            if(renderCallBack) {
                var modelRender=new ModelRender();
                var main = reactDom.renderToString(
                    <Provider store={store}>
                        <HkfsAbout/>
                    </Provider>
                );
                var initializeStore = JSON.stringify(store.getState());
                renderCallBack(modelRender.headerRender(),modelRender.barRender(),modelRender.footerRender(),main, initializeStore);
            }
        }
    );
};